package com.hadoop.demo.mapreduce.lottery;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * =================================
 * <p>
 * Created by Administrator on 2018/10/16.
 * <p>
 * 描述: 分析每一位彩票的个数，以及走势
 */

public class CountNumMapper extends Mapper<LongWritable, Text, Text, LongWritable> {


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();
        //split key
        String[] fields = StringUtils.split(line, "\t");

        for(int i=0;i<fields.length;i++){
            context.write(new Text((i+1)+":"+fields[i]), new LongWritable(1));
        }
    }
}
